/*
 * @Author: your name
 * @Date: 2021-05-11 16:45:50
 * @LastEditTime: 2021-05-12 11:08:10
 * @LastEditors: Please set LastEditors
 * @Description: In User Settings Edit
 * @FilePath: \after-end\app\utils\deduplicationRecursion.js
 */
function unique(arr) {
    if (!Array.isArray(arr)) {
        console.log('type error!')
        return
    }
    var array = [];
    for (var i = 0; i < arr.length; i++) {
        var index = i === arr.length - 1 ? 0 : i + 1;
        if (arr[i].key !== arr[index].key) {
            array.push(arr[i]);
            array.forEach(item => {
                if (item.children && item.children.length > 1) {
                    item.children = unique(item.children);
                }
            });
        }
    }
    return array
}

module.exports = {
    unique
}